﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace CJGL
{
   public static class SqlDAL
    {
        /// <summary>
        /// 获取剩余中码数量
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public static String GetHospitalList()
        {
            string sql = @"select count(1) from table_codes where is_user=0";

            SqlParameter[] parList = {
           
               };
            object tab = SqlDbHelper.ExecuteScalar(sql);
            if (tab==null)
            {
                return "";
            }
            return tab.ToString();
           
        }

        /// <summary>
        /// 根据用户ID获取卡券
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public static DataTable GetBarCode()
        {
            string sql = @"select top 1 * from table_codes where is_user=0 order by id ";

            SqlParameter[] parList = {

               };
            DataTable tab = SqlDbHelper.ExecuteDataTable(sql, parList);
            if (tab != null)
            {
                return tab;
            }
            return null;

        }
        /// <summary>
        /// 根据用户ID获取卡券
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public static int UpdateBarcode(int id)
        {
            string sql = @"update table_codes set is_user=1 where id="+id;

            int tab = SqlDbHelper.ExecuteNonQuery(sql);
            return tab;

        }
        /// <summary>
        /// 根据用户ID获取卡券
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public static int DeleteBarcode(string code)
        {
            string sql = @"delete from  table_codes where code_str='" + code+"'";

            int tab = SqlDbHelper.ExecuteNonQuery(sql);
            return tab;

        }
    }
}
